package com.ssy.lingxi.product.entity.price;

import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.ssy.lingxi.product.entity.Goods;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * 货品价格实体类
 * @author lxc
 * @version 2.0.0
 * @date 2022/3/25
 */
@Getter
@Setter
@Entity
@Table(schema = "public", name = "product_goods_price", indexes = {@Index(name = "product_goods_price_upper_member_id_upper_member_role_id_idx", columnList = "upperMemberId,upperMemberRoleId"),
        @Index(name = "product_goods_upper_member_name_idx", columnList = "upperMemberName")})
public class GoodsPrice implements Serializable {

    /**
     * 主键id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="goods_seq")
    @SequenceGenerator(sequenceName="product_goods_price_seq", name="goods_price_seq",allocationSize = 1)
    private Long id;

    /**
     * 货品信息
     */
    @OneToOne(cascade = {CascadeType.PERSIST})
    @JoinColumn(name="goods_id",referencedColumnName = "id")
    private Goods goods;

    /**
     * 市场价
     */
    @Column(columnDefinition = "decimal")
    private Double marketPrice= 0D;

    /**
     * 合同/订单价
     */
    @Column(columnDefinition = "decimal")
    private Double orderPrice = 0D;

    /**
     * 合同/订单编号
     */
    @Column(columnDefinition = "varchar(20)")
    private String code;

    /**
     * 供应会员id
     */
    @Column(columnDefinition = "int8")
    private Long upperMemberId;

    /**
     * 供应会员名称
     */
    @Column(columnDefinition = "varchar(50)")
    private String upperMemberName;

    /**
     * 供应会员角色id
     */
    @Column(columnDefinition = "int8")
    private Long upperMemberRoleId;

    /**
     * 价格有效开始时间
     */
    @Column(columnDefinition = "int8")
    private Long effectiveStartTime;

    /**
     * 价格有效截止时间
     */
    @Column(columnDefinition = "int8")
    private Long effectiveEndTime;

    /**
     * 创建时间
     */
    @Column(columnDefinition = "int8", nullable = false)
    private Long createTime = System.currentTimeMillis();

    /**
     * 修改时间
     */
    @Column(columnDefinition = "int8")
    private Long updateTime = System.currentTimeMillis();

    /**
     * 物料价格类型 在 GoodsPriceTypeEnum 中定义
     * 1:合同价格; 2:订单价格
     */
    @Column(columnDefinition = "int4")
    private Integer priceType= 1;

    /**
     * 物料状态 在 GoodsPriceStatusEnum 中定义
     * 1:正常; 2:变更; 3:到期; 4:停用; 5:作废;
     */
    @Column(columnDefinition = "int4", nullable = false)
    private Integer status=1;

    /**
     * 历史价格信息
     */
    @JsonManagedReference
    @OneToMany(mappedBy = "goodsPrice", cascade = {CascadeType.PERSIST, CascadeType.MERGE})
    private List<GoodsPriceHistory> priceHistorys;

}
